/*
 * Filename    : State_Menu_Level.java
 * Projectname : RamaShinta
 * Date        : Jan 22, 2013 , 5:01:06 PM 
 * 
 */

package com.amikomgamedev.ramashinta.state;

import org.andengine.entity.modifier.ScaleAtModifier;
import org.andengine.entity.scene.ITouchArea;
import org.andengine.entity.sprite.Sprite;
import org.andengine.input.touch.TouchEvent;

import com.amikomgamedev.ramashinta.ServerData;
import com.amikomgamedev.ramashinta.Utils;

import android.view.KeyEvent;

public class State_Menu_Level extends State_Menu_Help
{

	protected void create_Menu_Level()
	{
		graphic.spr_Button_Menu[0].setVisible(false);
		graphic.attachMenuLevel();
		text.createTextLevel();
		for(int i=0;i<text.Level.length;i++){
				int Row2 = 2;
						graphic.spr_Menu_Level_Bg.attachChild(text.Level[i]);
					if(i>=0&&i<5){
						text.Level[i].setY(Utils.getRatioH(80) + text.Level[i].getHeight());
					}
					if(i>=5&&i<10){
						text.Level[i].setY(RES_HEIGHT / Row2-text.Level[i].getHeight());
					}
//					if(i>4&&i<7){
//						spr_Menu_Level_Love[i].setY(RES_HEIGHT / Row3 - spr_Menu_Level_Love[i].getHeight() / Row3);
//					}
//					if(i==1){
//						spr_Menu_Level_Love[i].setX(Utils.getRatio(150) * (2));
//					}
					text.Level[i].setX(Utils.getRatio(120) * ((i%5)+1));
					Utils.TRACE("pos X text "+text.Level[i].getX());
					Utils.TRACE("pos Y text "+text.Level[i].getY());
			}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event)
	{

		if (State_Menu_Current == STATE_MENU_LEVEL)
		{
			if (keyCode == KeyEvent.KEYCODE_BACK)
			{
				switchState(STATE_MENU_STAGE);
				detachMenuLevel();
				// graphic.detachMenuLevel();

			}
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public boolean onAreaTouched(TouchEvent pSceneTouchEvent, ITouchArea pTouchArea, float pTouchAreaLocalX,
			float pTouchAreaLocalY)
	{
		if (State_Menu_Current == STATE_MENU_LEVEL)
		{
			if (pTouchArea.equals(graphic.spr_Menu_Level_Love[0]))
			{
				Utils.TRACE("klik 0");
				ServerData.setLevelSelection(ServerData.LEVEL_HUTAN);
				ServerData.setSelectedLevel(ServerData.LEVEL1);
				sound.stopMenuBgm();
				switchState(STATE_GAME_PLAY);
				detachMenuLevel();
				// graphic.detachMenuLevel();
			} else if (pTouchArea.equals(graphic.spr_Menu_Level_Love[1]))
			{
				Utils.TRACE("Klik 1");
				ServerData.setLevelSelection(ServerData.LEVEL_HUTAN);
				ServerData.setSelectedLevel(ServerData.LEVEL2);
				sound.stopMenuBgm();
				switchState(STATE_GAME_PLAY);
				detachMenuLevel();
				// graphic.detachMenuLevel();
			}else if (pTouchArea.equals(graphic.spr_Menu_Level_Love[2]))
			{
				ServerData.setLevelSelection(ServerData.LEVEL_HUTAN);
				ServerData.setSelectedLevel(ServerData.LEVEL3);
				sound.stopMenuBgm();
				switchState(STATE_GAME_PLAY);
				detachMenuLevel();
				// graphic.detachMenuLevel();
			}else if (pTouchArea.equals(graphic.spr_Menu_Level_Love[3]))
			{
				ServerData.setLevelSelection(ServerData.LEVEL_HUTAN);
				ServerData.setSelectedLevel(ServerData.LEVEL4);
				sound.stopMenuBgm();
				switchState(STATE_GAME_PLAY);
				detachMenuLevel();
				// graphic.detachMenuLevel();
			}else if (pTouchArea.equals(graphic.spr_Menu_Level_Love[4]))
			{
				ServerData.setLevelSelection(ServerData.LEVEL_HUTAN);
				ServerData.setSelectedLevel(ServerData.LEVEL5);
				sound.stopMenuBgm();
				switchState(STATE_GAME_PLAY);
				detachMenuLevel();
				// graphic.detachMenuLevel();
			}else if (pTouchArea.equals(graphic.spr_Menu_Level_Love[5]))
			{
				ServerData.setLevelSelection(ServerData.LEVEL_HUTAN);
				ServerData.setSelectedLevel(ServerData.LEVEL6);
				sound.stopMenuBgm();
				switchState(STATE_GAME_PLAY);
				detachMenuLevel();
				// graphic.detachMenuLevel();
			}else if (pTouchArea.equals(graphic.spr_Menu_Level_Love[6]))
			{
				ServerData.setLevelSelection(ServerData.LEVEL_HUTAN);
				ServerData.setSelectedLevel(ServerData.LEVEL7);
				sound.stopMenuBgm();
				switchState(STATE_GAME_PLAY);
				detachMenuLevel();
				// graphic.detachMenuLevel();
			}else if (pTouchArea.equals(graphic.spr_Menu_Level_Love[7]))
			{
				ServerData.setLevelSelection(ServerData.LEVEL_HUTAN);
				ServerData.setSelectedLevel(ServerData.LEVEL8);
				sound.stopMenuBgm();
				switchState(STATE_GAME_PLAY);
				detachMenuLevel();
				// graphic.detachMenuLevel();
			}else if (pTouchArea.equals(graphic.spr_Menu_Level_Love[8]))
			{
				ServerData.setLevelSelection(ServerData.LEVEL_HUTAN);
				ServerData.setSelectedLevel(ServerData.LEVEL9);
				sound.stopMenuBgm();
				switchState(STATE_GAME_PLAY);
				detachMenuLevel();
				// graphic.detachMenuLevel();
			}else if (pTouchArea.equals(graphic.spr_Menu_Level_Love[9]))
			{
				ServerData.setLevelSelection(ServerData.LEVEL_HUTAN);
				ServerData.setSelectedLevel(ServerData.LEVEL10);
				sound.stopMenuBgm();
				switchState(STATE_GAME_PLAY);
				detachMenuLevel();
				// graphic.detachMenuLevel();
			}
		}

		return super.onAreaTouched(pSceneTouchEvent, pTouchArea, pTouchAreaLocalX, pTouchAreaLocalY);
	}

	private void detachMenuLevel()
	{
		mEngine.runOnUpdateThread(new Runnable()
		{

			@Override
			public void run()
			{
				// TODO Auto-generated method stub
				graphic.detachMenuLevel();
			}
		});
	}
}
